package cn.kgc.ssm.service;

import cn.kgc.ssm.entity.User;
import cn.kgc.ssm.mapper.UserMapper;
import cn.kgc.ssm.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: mosin
 * @version: v1.0  2022/5/7
 */
@Service
public class UserServiceImpl implements UserService {
        @Autowired
        private UserMapper userMapper;
        @Override
        public Result login(User user) {
                User usr = userMapper.selectOne(user);
                if(usr!=null){
                    return  Result.builder().code(200).msg("ok").data(usr).build();

                }else{
                        return    Result.builder().code(500).msg("error").data(usr).build();
                }

        }

        @Override
        public Result register(User user) {

                int i = userMapper.saveUser(user);
                if(i>0){
                        return  Result.builder().code(200).msg("ok").data(i).build();
                }else{
                        return  Result.builder().code(500).msg("error").data(i).build();
                }
        }

        @Override
        public Result updateUser(User user) {
                int i = userMapper.updateUser(user);
                if(i>0){
                        return  Result.builder().code(200).msg("ok").data(i).build();
                }else{
                        return  Result.builder().code(500).msg("error").data(i).build();
                }
        }

        @Override
        public Result deleteUser(Integer id) {
                int i = userMapper.deleteUser(id);
                if(i>0){
                        return  Result.builder().code(200).msg("ok").data(i).build();
                }else{
                        return  Result.builder().code(500).msg("error").data(i).build();
                }
        }
}
